<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>updateTic 更新票号小弹窗</title>
	</head>
	<link rel="stylesheet" href="../css/common.css" />
	<style>
		body{
			background: #eeeeee;
		}
		.main{
			text-align:right;
			padding-top:28px;
			overflow:auto;
			width:480px;
		}
		input{
			height:27px;
			width:180px;
			border:1px solid #dadada;
			border-radius:3px;
			padding-left:10px;
			margin-left:10px;	
		}
		.main p{
			height:36px;
		}
		.btnBox{
			height:40px;
			width:100%;
			padding-top:10px;
			position:fixed;
			bottom:0;
			left:0;
			text-align:center;
			background:#eeeeee;
		}
		.sure,.cancel{
			height:28px;
			padding:0 35px;
			background:#00aa98;
			border:none;
			border-radius:3px;
			color:white;
			cursor:pointer;
		}
		.cancel{
			margin-left:30px;
			background:#a1a4a9;
		}
	</style>
	<body>
		<div class='main'>
					
		</div>
		<div style='height:50px;'></div>
		<div class='btnBox'>
			<button class='sure'>确认</button>
			<button class='cancel'>取消</button>
		</div>
		<script type="text/javascript" src="../js/jquery-1.12.4.js" ></script>		
		<script type="text/javascript" src="../js/common.js" ></script>
		<script type="text/javascript" src="../layer-v2.4/layer/layer.js" ></script>
		<script>
		var orderId = getHref().orderId;
		var type = getHref().type;
		console.log(type)

		//_______________________________________________________________确定按钮
				$(".sure").click(function(){
					var url = "";
					var len=$(".ticketNums").length;//获取表格行数
					var dataArr = [];	//定义数组list用于装每条所需的数据	
					for(var i=0;i<len;i++){
						var json={};
						json.ticketNumber = $(".ticketNums").eq(i).val();
						json.passengerId = $(".passengerId").eq(i).text();
						/* if(json.ticketNumber==""){
							layer.msg("请输入所有票号",{icon: 2,time:1500})
							return false
						} */
						/* if(!/^\d{3}(\-\d+)?\d{1,}$/.test(json.ticketNumber)||json.ticketNumber.length>18){
							layer.msg("票号格式不正确",{icon:2,time:1500});
							return false;
						} */
						dataArr.push(json)
						console.log(dataArr)
					}
					layer.msg('更新票号中...', {icon: 16,shade: 0.01});
					
					//将得到的数据传输给后台
					if(type=="common"){
						url += "../order/"+orderId+"/ticket?temp="+Math.random();
					}
					if(type=="connect"){
						url += "../order/"+orderId+"/connectTicket?temp="+Math.random();
					}
					 $.ajax({
							type:"post",
							url:url,
							contentType:'application/json;charset=utf-8',
							data:JSON.stringify(dataArr),
							async:true,
							success:function(data){
								var data=JSON.parse(data);								
								if(data.status.toString()=="1001"){
									layer.msg(data.message, {icon: 1,time:1000},function(){
										var index = parent.layer.getFrameIndex(window.name);//获取弹窗索引
										parent.layer.close(index);//关闭弹窗
									});			
								}else{
									layer.msg(data.message, {icon: 2,time:1000})
								}
							}
						});
					
					
				});
		
		//_______________________________________________________________页面渲染
			var postUpdateTicketsJson = parent.postUpdateTicketsJson;
		console.log(postUpdateTicketsJson)
			var nameArr = postUpdateTicketsJson.nameArr;
			var passengerIdArr = postUpdateTicketsJson.passengerIdArr;
			var certificateNumberArr = postUpdateTicketsJson.certificateNumberArr;
			var ticketsNumberArr = postUpdateTicketsJson.ticketsNumberArr;
			
			var str="";
			for(var i=0;i<nameArr.length;i++){
				var ticketsNumber = ticketsNumberArr[i]?ticketsNumberArr[i]:"";
				str+="<p><span>"+nameArr[i]+"</span><span>("+certificateNumberArr[i]+")</span><input type='text' class='ticketNums' value="+ticketsNumber+"><span style=display:none; class=passengerId>"+passengerIdArr[i]+"</span></p>"
			}
			$(".main").append(str);		
			
		//_______________________________________________________________取消按钮
			$(".cancel").click(function(){
				closeWin()
			})
		
		
		</script>
	</body>
</html>
